package com.example.child_protection.dto.base;

import com.example.child_protection.enums.BooleanEnums;
import com.example.child_protection.validata.BeanValidators;
import com.example.child_protection.validata.GidGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiParam;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
public abstract class BaseRequestDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiParam( hidden = true )
    @JsonIgnore
    private String gid;

    @ApiParam( hidden = true )
    @JsonIgnore
    private Long operatorId;

    @ApiParam( hidden = true )
    @JsonIgnore
    private String operator;

    @ApiParam( hidden = true )
    @JsonIgnore
    private String operatorOrgId;

    protected abstract boolean isValidGid();

    public abstract void valid();

    public void valid( Object object, Class<?>... groups ) {
        this.validate( object, groups );
    }


    protected final void validate( Object object, Class<?>... groups ) {
        if ( 0 == groups.length ) {
            groups = ( Class[] ) ArrayUtils.add( groups, Default.class );
        }

        if ( isValidGid() ) {
            groups = ( Class[] ) ArrayUtils.add( groups, GidGroup.class );
        }

        String errorMessages = BeanValidators.validateWithString( object, groups );

        if ( StringUtils.isNotBlank( errorMessages ) )
            throw new IllegalArgumentException( errorMessages );
    }
    /**
     * 添加人id
     */
    @ApiParam( hidden = true )
    private Long createPersonId;

    /**
     * 最后修改人id
     */
    @ApiParam( hidden = true )
    private Long lastUpdatePersonId;

}
